﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pic_alldown.aspx.cs" Inherits="admin_pic_alldown" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="Stylesheet" rev="Stylesheet" href="images/style.css" />
    <script type="text/javascript" src="../Scripts/jquery.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.progressbar.min.js"></script>
    <script type="text/javascript">
        $.ajaxSetup({timeout:1000*3600*12});
        var downloadtp = function (obj) {
            tpcount = 0;
            var urls = obj.tpurl.split('|');
            for (var i = 0; i < urls.length; i++) {
                if (urls[i] != null && urls[i] != "") {
                    $.getJSON("pic_down.aspx?_t=" + new Date(), { url: urls[i], tpadd: obj.tpadd },
                        function (msg) {
                            tpcount++;
                            if (msg.success == "true") {
                                $('#pbzj').progressBar(tpcount);
                                //var name = this.data.split("&")[0].split("%2F")[this.data.split("&")[0].split("%2F").length-1];
                                //$("#picsDiv").html($("#picsDiv").html() + "<img alt="+name+" width=110 height=160 src='/comicdata/"+obj.tpadd+name+"'/>");
                            } else {
                                document.getElementById("errorText").innerText += msg.error + "<br>";
                            }
                            if (tpcount == obj.tps) {
                                $.getJSON("server.aspx?a=downloadComplete&_t=" + new Date(), { zjid: obj.zjid },
                                        function () {
                                            count++;
                                            $('#pbmain').progressBar(count,{ max: <%= dcount %> , textFormat: 'fraction', barImage: '../images/progressbar/progressbg_red.gif' });
                                            if (iscontinue) {
                                                $("#picsDiv").html("");
                                                startDownload();
                                            }
                                        });
                            }
                        });
                }
            }
        }

        var mulidownloadtp = function () {
            if (confirm('确定批量下载!?')) {
                var checkboxs = document.getElementsByName("zjcheckbox");
                for (var i = 0; i < checkboxs.length; i++) {
                    if (checkboxs[i].checked) {
                        downloadtp(checkboxs[i].value);
                    }
                }
            }
        }

        var iscontinue = false;
        var tpcount = 0;
        var count = 0;
        var startDownload = function () {
            iscontinue = true;
            $.getJSON("server.aspx?a=getTopDownload&_t=" + new Date(), { strwhere: $("#tpadd_s").val() },
                    function (data) {
                        if (data.error == undefined) {
                            if (data.length == 0) {
                                document.getElementById("errorText").innerText += "更新完成<br>";
                                return;
                            }
                            for (var id in data[0]) {
                                if (id == "mhfm") {
                                    $("#" + id).attr("src", "../cpic/" + data[0][id]);
                                } else {
                                    $("#" + id).html(data[0][id]);
                                }
                            }
                            $('#pbzj').progressBar({ max: data[0].tps, textFormat: 'fraction', barImage: '../images/progressbar/progressbg_yellow.gif' });
                            downloadtp(data[0]);
                        } else {
                            document.getElementById("errorText").innerText += data.error + "<br>";
                        }
                    });
        }

        var stopDownload = function () {
            iscontinue = false;
        }

        function checkExist(){
            $.getJSON("server.aspx?a=checkExistDirectory&_t=" + new Date(), { strwhere: $("#tpadd_s").val() },
                    function (data) {
                        alert(data);
                    });
        }
    </script>
    <style type="text/css">
        .style1
        {
            width: 133px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align: center">
        <h2>
            漫画下载
        </h2>
        <table style="width: 100%; background-color: #CCCCCC;" cellpadding="3" cellspacing="1"
            width="98%" border="0">
            <tr>
                <td align="right" class="style1">
                    总进度
                </td>
                <td align="left">
                    <span class="progressBar" id='pbmain'></span>
                    <script type="text/javascript">
                        $('#pbmain').progressBar({ max: <%= dcount %> , textFormat: 'fraction', barImage: '../images/progressbar/progressbg_red.gif' });
                    </script>
                </td>
                <td rowspan="5">
                    <img alt="封面" id="mhfm" src="" />
                </td>
            </tr>
            <tr>
                <td align="right" class="style1">
                    漫画
                </td>
                <td align="left" id="mhmc">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td align="right" class="style1">
                    章节名称
                </td>
                <td align="left" id="zjmc">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td align="right" class="style1">
                    路径
                </td>
                <td align="left" id="tpadd">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td align="right" class="style1">
                    章节进度
                </td>
                <td align="left">
                    <span class="progressBar" id='pbzj'></span>
                </td>
            </tr>
        </table>
        路径：<input id="tpadd_s" type="text" />
        <input name="act" type="button" class="Submit" id="act" title="开始" onclick="startDownload()"
            value="开始" dir="ltr" />&nbsp;
        <input name="act0" type="button" class="Submit" id="act0" title="停止" onclick="stopDownload()"
            value="停止" />
        <input name="act0" type="button" id="Button1" title="已存在" onclick="checkExist()"
            value="已存在" />
        <div id="picsDiv" style="font-size: small; color: Red; text-align: left; vertical-align: top;">
        </div>
        <div id="errorText" style="font-size: small; color: Red;">
        </div>
    </div>
    </form>
</body>
</html>
